/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.poemPoet.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.poemPoet.domain.PoemPoetComment;
import me.zhengjie.poemPoet.domain.vo.domain.vo.PoemPoetCommentQueryCriteria;
import me.zhengjie.poemPoet.service.PoemPoetCommentService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
* @author yellow
* @date 2025-04-20
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "PoemPoetComment管理")
@RequestMapping("/api/poemPoet/comment")
public class PoemPoetCommentController {

    private final PoemPoetCommentService poemPoetCommentService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @AnonymousAccess
    public void exportPoemPoetComment(HttpServletResponse response, PoemPoetCommentQueryCriteria criteria) throws IOException {
        poemPoetCommentService.download(poemPoetCommentService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询PoemPoetComment")
    @ApiOperation("查询PoemPoetComment")
    @AnonymousAccess
    public ResponseEntity<PageResult<PoemPoetComment>> queryPoemPoetComment(PoemPoetCommentQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(poemPoetCommentService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增PoemPoetComment")
    @ApiOperation("新增PoemPoetComment")
    @AnonymousAccess
    public ResponseEntity<Object> createPoemPoetComment(@Validated @RequestBody PoemPoetComment resources){
        poemPoetCommentService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改PoemPoetComment")
    @ApiOperation("修改PoemPoetComment")
    @AnonymousAccess
    public ResponseEntity<Object> updatePoemPoetComment(@Validated @RequestBody PoemPoetComment resources){
        poemPoetCommentService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除PoemPoetComment")
    @ApiOperation("删除PoemPoetComment")
    @AnonymousAccess
    public ResponseEntity<Object> deletePoemPoetComment(@RequestBody List<Integer> ids) {
        poemPoetCommentService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}